<template>
  <view class="work-container">
    <!-- 轮播图 -->
    <uni-swiper-dot class="uni-swiper-dot-box" :info="bannerList" :current="current" field="content">
      <swiper class="swiper-box" :current="swiperDotIndex" @change="changeSwiper">
        <swiper-item v-for="(item, index) in bannerList" :key="index">
          <view class="swiper-item" @click="clickBannerItem(item)">
            <image :src="item.image" mode="aspectFill" :draggable="false" />
          </view>
        </swiper-item>
      </swiper>
    </uni-swiper-dot>
    <!-- 宫格组件 -->
    <me-section :title="$t('home.libManage')" type="line" />
    <view class="grid-body">
      <uni-grid :column="2" :showBorder="false" @change="changeGrid">
        <uni-grid-item v-for="(cItem, cIndex) in menuList" :key="cIndex" :index="cIndex">
          <view class="grid-item-box">
            <view v-if="['icon'].includes(cItem.type)" class="iconfont item_icon" :class="cItem.icon"></view>
            <uni-icons v-else :type="cItem.icon" size="40"></uni-icons>
            <text class="text">{{cItem.label}}</text>
          </view>
        </uni-grid-item>
      </uni-grid>
    </view>
  </view>
</template>

<script>
  import meSection from '../../components/ui/me-section/index.vue';
  export default {
    components:{
      meSection
    },
    data() {
      return {
        current: 0,
        swiperDotIndex: 0,
        bannerList: [
          {
            image: '/static/images/banner/banner3.png'
          },
          {
            image: '/static/images/banner/banner1.png'
          },
          {
            image: '/static/images/banner/banner2.png'
          },
        ],
        menuList:[
          // {
          //   type:'uni-icon',
          //   label:'货品码打印',
          //   icon:'staff-filled',
          //   path:'/pages/print/print'
          // },
          {
            type:'icon',
            label:this.$t('home.otherProvinces')+this.$t('home.allocation'),
            icon:'icon-kongbaiye-32',
            path:'/pages/record/list?type=3&pageName='
          },
          {
            type:'icon',
            label:this.$t('home.finishedProduct')+this.$t('home.allocation'),
            icon:'icon-chengpintiaobo',
            path:'/pages/record/list?type=4&pageName=',
          },
          {
            label:this.$t('home.stock')+this.$t('home.adjust')+'('+this.$t('home.out')+')',
            icon:'icon-chuku',
            type:'icon',
            path:'/pages/record/list?type=1&pageName='
          },
          {
            type:'icon',
            label:this.$t('home.stock')+this.$t('home.adjust')+'('+this.$t('home.enter')+')',
            icon:'icon-ruku',
            path:'/pages/record/list?type=2&pageName='
          },
          {
            type:'icon',
            label:this.$t('home.saleOut'),
            icon:'icon-xiaoshouchukudan',
            path:'/pages/record/list?type=6&pageName='
          }
        ]
      }
    },
    onShow() {
      this.$nextTick(()=>{
        uni.setNavigationBarTitle({
          title: this.$t('home.home')
        });
      })
    },
    methods: {
      clickBannerItem(item) {
        console.info(item)
      },
      changeSwiper(e) {
        this.current = e.detail.current
      },
      changeGrid(e) {
        const index = e.detail.index
        const itemInfo = this.menuList[index]
        console.log('menuList',index,itemInfo)
        if(itemInfo.path){
          this.$tab.navigateTo(String(itemInfo.path).replace('pageName=','pageName='+itemInfo.label))
        }else{ 
          this.$modal.showToast(this.$t('common.develop')) 
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background-color: #fff;
    min-height: 100%;
    height: auto;
  }

  view {
    font-size: 14px;
    line-height: inherit;
  }

  /* #endif */

  .text {
    text-align: center;
    font-size: 26rpx;
    margin-top: 10rpx;
  }
  /deep/ .grid-body{
    .uni-grid-wrap{
      .uni-grid{
        .uni-grid-item{
          height: 100px !important;
        }
      }
    }
  }

  .grid-item-box {
    flex: 1;
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0px 0;
  }
  .item_icon{
    font-size: 40px;
  }

  .uni-margin-wrap {
    width: 690rpx;
    width: 100%;
    ;
  }

  .swiper {
    height: 300rpx;
  }

  .swiper-box {
    height: 150px;
  }

  .swiper-item {
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    height: 300rpx;
    line-height: 300rpx;
  }

  @media screen and (min-width: 500px) {
    .uni-swiper-dot-box {
      width: 400px;
      /* #ifndef APP-NVUE */
      margin: 0 auto;
      /* #endif */
      margin-top: 8px;
    }

    .image {
      width: 100%;
    }
  }
</style>
